package com.jsmile.cloud.authc.sys.controller;

import javax.validation.Valid;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jsmile.cloud.authc.api.req.sys.ReqSysLogQuery;
import com.jsmile.cloud.authc.api.res.ResSysLog;
import com.jsmile.cloud.authc.sys.SysLogApplicationService;
import com.jsmile.mail.security.controller.AuthcController;
import com.jsmile.mail.security.handler.JsmileContext;
import com.jsmile.mall.api.JSmileResult;
import com.jsmile.mall.api.annotation.CurrentContext;
import com.jsmile.mall.api.to.JsmilePage;

import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author 龚亮
 * @version 1.0
 * @desc 控制器
 * @date 2018年08月25日 04:57:24
 */
@RestController
@Api(tags = "日志管理")
@Slf4j
@AllArgsConstructor
@RequestMapping("/sys/log")
public class SysLogController extends AuthcController {

    private final SysLogApplicationService sysLogApplicationService;

    @RequestMapping(value = "/findAll", method = RequestMethod.POST)
    public JSmileResult<JsmilePage<ResSysLog>> getPageList(@RequestBody @Valid ReqSysLogQuery reqSysLogQuery, @CurrentContext JsmileContext jsmileContext) {
        reqSysLogQuery.setCurTenantId(jsmileContext.getTenantId());
        IPage<ResSysLog> pages = sysLogApplicationService.getPageList(reqSysLogQuery);
        return JSmileResult.success(new JsmilePage(reqSysLogQuery.getPageIndex(), reqSysLogQuery.getPageSize(), pages.getTotal(), pages.getRecords()));
    }
}
